Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exception thrown in CLI when bicepconfig.json is invalid #4348

Merged
merged 7 commits into from
Sep 20, 2021

Conversation

bhsubra
Copy link
Contributor

@bhsubra bhsubra commented Sep 8, 2021

Fixes #4242

Without changes in this PR, with invalid bicepconfig.json, we throw unhandled exception:
image

As part of this PR, made changes to handle the exception gracefully
Fix4348

@bhsubra bhsubra requested a review from majastrz September 8, 2021 22:46
var compilation = new Compilation(this.invocationContext.ResourceTypeProvider, sourceFileGrouping);
try
{
var compilation = new Compilation(this.invocationContext.ResourceTypeProvider, sourceFileGrouping);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compilation

Wouldn't this also happen in the language server? I think we should make it so the compilation doesn't throw when the config file is malformed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically the reasoning is that the user can get much of the functionality even with a malformed config file, so the compilation shouldn't just give up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like I mentioned in the below comment, Compilation needs a valid config. If we encounter an invalid config, should we surface exception to user, create default disabled linter config and proceed with creating compilation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created below issue to track the issue on language server side:
#4471

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made changes to write error message and go ahead with compilation creation:
699af2a


return compilation;
}
catch (Exception exception)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exception

We shouldn't blindly catch all the exceptions and turn them into diagnostics.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, we do this in language server as well:

// this is a fatal error likely due to a code defect

On the language server side, if the config file is invalid, we don't proceed till config file is error free. The current compilation design needs a config file.

What do we want the behavior to be? If we encounter invalid config file, log diagnostic and use default config settings? That would be confusing.

One option I can think of:

Let me know your thoughts. Adding @anthony-c-martin as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should definitely surface the exception to the user, but until now, we've just relied on the try-catch in Program.RunAsync for this. Is there a reason to write a diagnostic instead of following this pattern?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean use InvocationContext to write error? That would look like this:
image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah - in the above screenshot, the exception message itself is definitely useful, but I don't think there's any need to log the stack trace. The only thing I'd change in the message is making sure we log which file couldn't be parsed - so the user knows where to look for the bad configuration file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created below issue to track the issue on language server side:
#4471

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made changes to write error message and go ahead with compilation creation:
699af2a

@bhsubra bhsubra force-pushed the dev/bhsubra/Fix4242 branch from d9c342b to 699af2a Compare September 17, 2021 00:06
@majastrz majastrz merged commit 147361f into main Sep 20, 2021
@majastrz majastrz deleted the dev/bhsubra/Fix4242 branch September 20, 2021 23:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Empty bicepconfig.json breaks CLI
3 participants